<template>
	<view class="table_box">
		<view>
			<text>{{todayDate}}</text>
		</view>
		<view class="timeall d-rn d-jb">
			<u-icon name="arrow-left" color="#8F9BB3" size="32rpx" class="left" @click="lastclick"></u-icon>
			<view class="timeall-all">
				<view class="table_header">
					<view class="weekday" v-for="(item,index) in weekAll" :key="index">
						<text>{{item}}</text>
					</view>
				</view>
				<view class="table_header">
					<view class="weekday" :class="item.adate==todayDate?'finish':'test'"
						v-for="(item,index) in weekDayArr" :key="index">
						<text @click="getAdate(item)">{{item.adate.slice(7,9)}}</text>
					</view>
				</view>

			</view>
			<u-icon name="arrow-right" color="#8F9BB3" size="32rpx" class="right" @click="nextclick"></u-icon>
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				currentFirstDate: "",
				clen: 7,
				todayDate: "",
				weekDayArr: [],
				weekAll: [
					'周一', '周二', '周三', '周四', '周五', '周六', '周日',
				]
			}
		},
		created() {
			this.todayDate = this.formatDate(new Date())
			this.setDate(new Date())
		},
		methods: {
			// 日期格式处理
			formatDate(date) {
				console.log(date)
				var year = date.getFullYear() + '-'
				var month = (date.getMonth() + 1) + '-';
				var day = date.getDate();
				return year + month + day;
			},
			//
			addDate(date, n) {
				date.setDate(date.getDate() + n);
				return date;
			},
			//
			setDate(date) {
				var week = date.getDay() - 1;
				date = this.addDate(date, week * -1);
				this.currentFirstDate = new Date(date);
				for (var i = 0; i < this.clen; i++) {
					this.weekDayArr.push({
						"adate": this.formatDate(i == 0 ? date : this.addDate(date, 1))
					})
				}
			},
			//上一周
			lastclick() {
				this.weekDayArr = []
				this.setDate(this.addDate(this.currentFirstDate, -7));
			},
			//下一周
			nextclick() {
				this.weekDayArr = []
				this.setDate(this.addDate(this.currentFirstDate, 7));
			},
			getAdate(item) {
				console.log(item)
			}
		},
	}
</script>
<style lang="scss">
	.table_box{
		padding:0 24rpx;
		box-sizing: border-box;
	}
	.timeall {
		position: relative;
		width: 100%;
	}

	.lastbt,
	.nextbt {
		position: absolute;
		top: 18px;
	}

	.lastbt {
		left: -7px;
	}

	.nextbt {
		right: -7px;
	}
	.timeall-all{
		width: 90%;
	}
	.table_header {
		display: flex;
		justify-content: center;
		color: #999999;
	}

	.week_one {
		text-align: center;
		line-height: 50px;
		border-bottom: 1px solid #f5f4f7;
		border-left: 1px solid #f5f4f7;
		background: #F5F5F5;
		width: 200px;
	}

	.weekday {
		flex: 1;
		text-align: center;
		line-height: 25px;
	}

	.finish {
		background: #ffd03d;
		color: #fff !important;
	}
</style>